home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / sound / sndblst4.zip / SBC.C < prev    next >
Text File  |  1993-12-11  |  4KB  |  148 lines

  1.  
  2. //------------------------------------------------------------------------------
  3. // Copyright (c), David Welch, 1993
  4. //------------------------------------------------------------------------------
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include <alloc.h>
  10. #include <string.h>
  11. #include <mem.h>
  12.  
  13. void dspwrite ( unsigned char );
  14. unsigned char dspread ( void );
  15.  
  16. unsigned char *data;
  17. unsigned char *aligned;
  18. unsigned char aligned_physical;
  19. //------------------------------------------------------------------------------
  20. void dspwrite ( unsigned char c )
  21. {
  22.     while(inportb(0x022C)&0x80);
  23.     outportb(0x022C,c);
  24. }
  25. //------------------------------------------------------------------------------
  26. unsigned char dspread ( void )
  27. {
  28.     while(!(inportb(0x22E)&0x80));
  29.     return(inportb(0x22A));
  30. }
  31. //------------------------------------------------------------------------------
  32. void sbinit ( void )
  33. {
  34.     unsigned short x;
  35.     inportb(0x022E);
  36.     outportb(0x0226,0x01);
  37.     inportb(0x0226);
  38.     inportb(0x0226);
  39.     inportb(0x0226);
  40.     inportb(0x0226);
  41.     outportb(0x0226,0x00);
  42.     for(x=0;x<100;x++)
  43.     {
  44.         if(inportb(0x022E)&0x80)
  45.         {
  46.             if(inportb(0x022A)==0xAA) break;
  47.         }
  48.     }
  49.     if(x==100)
  50.     {
  51.         printf("Sound Blaster not found at 0220h\n");
  52.         exit(1);
  53.     }
  54. }
  55. //------------------------------------------------------------------------------
  56. void sbmalloc ( void )
  57. {
  58.     unsigned long physical;
  59.     data=farmalloc(131000L);
  60.     if(data==NULL)
  61.     {
  62.         printf("Memory Allocation Error\n");
  63.         exit(1);
  64.     }
  65.     physical=((unsigned long)FP_OFF(data))+(((unsigned long)FP_SEG(data))<<4);
  66.     physical+=0x0FFFFL;
  67.     physical&=0xF0000L;
  68.     aligned_physical=(physical>>16)&15;
  69.     aligned=MK_FP(((unsigned short)aligned_physical<<12)&0xF000,0);
  70. }
  71. //------------------------------------------------------------------------------
  72. void sbsettc ( unsigned char tc )
  73. // tc = time constant = 256L - (1000000UL/samples per second)
  74. {
  75.     inportb(0x022E);
  76.     dspwrite(0x40);
  77.     dspwrite(tc);
  78. }
  79. //------------------------------------------------------------------------------
  80. void sbhaltdma ( void )
  81. {
  82.     dspwrite(0xD0);
  83. }
  84. //------------------------------------------------------------------------------
  85. void spkon ( void )
  86. {
  87.     dspwrite(0xD1);
  88. }
  89. //------------------------------------------------------------------------------
  90. void spkoff ( void )
  91. {
  92.     dspwrite(0xD3);
  93. }
  94. //------------------------------------------------------------------------------
  95. void sbplay ( unsigned short len )
  96. // len = number of bytes pointed to by unsigned char *aligned (<=65000)
  97. {
  98.     len--;
  99.     outportb(0x0A,0x05);
  100.     outportb(0x0C,0x00);
  101.     outportb(0x0B,0x49);
  102.     outportb(0x02,0);
  103.     outportb(0x02,0);
  104.     outportb(0x83,aligned_physical);
  105.     outportb(0x03,(unsigned char)(len&0xFF));
  106.     outportb(0x03,(unsigned char)((len>>8)&0xFF));
  107.     outportb(0x0A,0x01);
  108.     dspwrite(0x14);
  109.     dspwrite((unsigned char)(len&0xFF));
  110.     dspwrite((unsigned char)((len>>8)&0xFF));
  111. }
  112. //------------------------------------------------------------------------------
  113. void sbrec ( unsigned short len )
  114. // len = number of bytes to record to unsigned char *aligned (<=65000)
  115. {
  116.     len--;
  117.     outportb(0x0A,0x05);
  118.     outportb(0x0C,0x00);
  119.     outportb(0x0B,0x45);
  120.     outportb(0x02,0);
  121.     outportb(0x02,0);
  122.     outportb(0x83,aligned_physical);
  123.     outportb(0x03,(unsigned char)(len&0xFF));
  124.     outportb(0x03,(unsigned char)((len>>8)&0xFF));
  125.     outportb(0x0A,0x01);
  126.     dspwrite(0x24);
  127.     dspwrite((unsigned char)(len&0xFF));
  128.     dspwrite((unsigned char)((len>>8)&0xFF));
  129. }
  130. //------------------------------------------------------------------------------
  131. unsigned short dmacount ( void )
  132. {
  133.     unsigned short x;
  134.     x=inportb(0x03);
  135.     x|=inportb(0x03)<<8;
  136.     if(x==0xFFFF) inportb(0x022E);
  137.     return(x);
  138. }
  139. //------------------------------------------------------------------------------
  140. unsigned short dmastatus ( void )
  141. {
  142.     return(inportb(0x0008)&2);
  143. }
  144. //------------------------------------------------------------------------------
  145. // Copyright (c), David Welch, 1993
  146. //------------------------------------------------------------------------------
  147.  
  148.